package file

import (
	"fmt"
	"io/ioutil"
	"os"
)

func GetFile(path string) *os.File {
	file, e := os.Open(path)
	if e != nil {
		fmt.Println(e.Error())
		return new(os.File)
	}
	return file
}

func GetContent(f *os.File) string {
	result := []byte{}
	for {
		buf := make([]byte, 1024)
		n, e := f.Read(buf)
		if e != nil {
			break
		}
		if n > 0 {
			result = append(result, buf...)
		} else {
			break
		}
	}
	return string(result)
}

func ReadFile(path string) string {
	file := GetFile(path)
	return GetContent(file)
}

func ReadAll(path string) string {
	content, _ := ioutil.ReadFile(path)
	return string(content)
}
